package cn.hinglo.gameclaw.im.action;

import cn.hinglo.gameclaw.data.entity.Result;
import cn.hinglo.gameclaw.im.service.ChatRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @createTime: 2018/3/6
 * @author: HingLo
 * @description: 娃娃机的房间(聊天室)管理, 用于管理弹幕
 */
@RestController
@RequestMapping("/im/r/")
public class ChatRoomAction {
    private final ChatRoomService chatRoomService;

    @Autowired
    public ChatRoomAction(ChatRoomService chatRoomService) {
        this.chatRoomService = chatRoomService;
    }


    /**
     * 聊天室查询
     *
     * @param roomId 房间Id
     * @return 返回聊天室的基本信息
     */
    @GetMapping("query/room")
    public Result queryRoomInfo(@RequestParam(value = "roomId") Long roomId) {
        return chatRoomService.queryRoomInfoService(roomId);
    }

    /**
     * 创建一个聊天室
     *
     * @param creator 创建人的Id
     * @param name    聊天室的名称
     * @return 创建结果
     */
    @PostMapping("create/room")
    public Result createRoomAction(String creator, String name) {
        return chatRoomService.createRoomService(creator, name);
    }

    /**
     * 更新聊天室的信息
     *
     * @param roomId       聊天室的Id
     * @param name         聊天室的名称
     * @param announcement 聊天室的公告
     * @return 更新结果
     */
    @PostMapping("update/room")
    public Result updateRoomAction(long roomId, String name, String announcement) {
        return chatRoomService.updateRoomService(roomId, name, announcement);

    }

    /**
     * 更新房间的状态
     *
     * @param roomId   房间Id
     * @param operator 创建人
     * @param valid    是否打开聊天室
     * @return 操作结果
     */
    @PostMapping("status/room")
    public Result updateRoomStatusAction(long roomId, String operator, boolean valid) {
        return chatRoomService.updateRoomStatusService(roomId, operator, valid);
    }

}
